/*
 * VHRoundSelector.java
 * Created on 2 août 2009
 *
 * VirtualHockey Internet Platform
 * http://code.google.com/p/virtualhockey/
 *
 * Copyright (c) 2005-2009, Jens and Jan Janke (VirtualHockey Project)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */
package com.hockeo.vhweb.client.ui.widget;

import java.util.List;

import com.hockeo.vhweb.client.rpc.VHRpcResultReceiver;
import com.hockeo.vhweb.client.ui.base.VHSelector;
import com.hockeo.vhweb.client.utils.VHJsData;

/**
 * Dropdown list allowing to select between different contest rounds.
 *
 * @version $Id$
 * @author jjanke
 */
public class VHRoundSelector extends VHSelector implements VHRpcResultReceiver<List<VHJsData>>
{
  public VHRoundSelector()
  {
    getCombobox().setDisplayField( "roundType_translated" );
    getCombobox().setValueField( "id" );
    getCombobox().setWidth( 200 );
  }

  public void setRpcData( List<VHJsData> listRounds, String strPurpose )
  {
    VHJsData roundSelected = null;

    for ( VHJsData round : listRounds )
    {
      if ( round.getBoolean( "inProgress" ) )
      {
        roundSelected = round;
        break;
      }
      else if ( round.getBoolean( "played" ) )
        roundSelected = round;
      else
        break;
    }

    getStore().removeAll();
    getStore().add( listRounds );

    // select active round
    //
    if ( roundSelected != null )
      getCombobox().setValue( roundSelected );

    setInitialised( true );
  }
}
